﻿import clr
clr.AddReference('System.Web')
clr.AddReference('System.Data')

from System.Web.UI import *
from System.Web.UI.WebControls import *
from IronSharePoint import *
from Microsoft.SharePoint.WebControls import *
from Microsoft.SharePoint import *
from System.Data import *

settings = IronSettings.Current

def OnInit(args):
	global action
	action = self.Request["Action"]
	
	global trustedLocation
	trustedLocation = self.Request["TrustedLocation"]
	
	bSave.Click += SaveTrustedLocation	
	
def OnLoad(args):
	if action == "delete":
		settings.TrustedLocations.Remove(trustedLocation)

		web = SPContext.Current.Web
		web.AllowUnsafeUpdates = True
		settings.Update()
		web.AllowUnsafeUpdates = False
		self.Response.Redirect("IronSettings.aspx")
		return
	
	if self.IsPostBack == False and action == "edit":
		tbUrl.Text = trustedLocation
		

		
def SaveTrustedLocation(sender, args):
	if action == "edit":
		index = settings.TrustedLocations.IndexOf(trustedLocation)
		settings.TrustedLocations[index] = tbUrl.Text
	else:
		settings.TrustedLocations.Add(tbUrl.Text)	
	
	settings.Update()
	
	self.Response.Redirect("IronSettings.aspx")